#include<pthread.h>
// RAII
// 分成两个类可以降低耦合度
class MutexGuard
{
public:
    MutexGuard(pthread_mutex_t* mutex)
    : _mutex(mutex)
    {
        pthread_mutex_lock(_mutex);     //注意在用RAII锁+全局变量锁时就不要调用锁的初始化和销毁的接口了
    }

    ~MutexGuard()
    {
        pthread_mutex_unlock(_mutex);
    }
private:
    pthread_mutex_t* _mutex;
};
